<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成背包问题实例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f7fc;
        }
        .item-list {
            list-style-type: none; /* 去除列表符号 */
            padding: 0; /* 去除默认的内边距 */
        }

        .item-list li {
            margin-bottom: 5px; /* 列表项之间的间距 */
            padding: 5px; /* 列表项的内边距 */
            background-color: #fff; /* 列表项的背景颜色 */
            border: 1px solid #eee; /* 列表项的边框 */
        }

        .item-name, .item-weight, .item-value {
            font-weight: bold; /* 加粗字体 */
        }

        .capacity {
            font-weight: bold; /* 加粗字体 */
            color: #333; /* 字体颜色 */
        }
        .container {
            max-width: 800px;
            margin: 30px auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
            font-size: 24px;
        }
        form {
            margin-bottom: 20px;
        }
        label {
            font-size: 16px;
            margin-right: 10px;
            color: #333;
        }
        input[type="number"], select, input[type="text"] {
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 10px;
            width: 100%;
            max-width: 200px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            max-width: 200px;
            margin-top: 10px;
        }
        button:hover {
            background-color: #45a049;
        }
        .array-display span {
            display: inline-block;
            width: 60px;
            padding: 5px;
            text-align: center;
            margin-right: 5px;
            margin-bottom: 5px;
            background-color: #e4e4e4;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .array-display span:nth-child(10n) {
            margin-right: 0;
        }
        .result {
            margin-top: 20px;
            font-size: 18px;
            color: #333;
            padding: 10px;
            background-color: #e9f7e9;
            border: 1px solid #d1e7d1;
            border-radius: 5px;
        }
        .error {
            color: red;
            font-size: 16px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>手动输入背包参数和物品参数</h1>

        <form method="post">
            {% csrf_token %}
            <div>
                <label for="n">请输入物品数量 (n)：</label>
                <input type="number" id="n" name="n" required min="1"> <br>
                <label for="weights">请输入物品重量 （以逗号分隔）：</label>
                <input type="text" id="weights" name="weights"> <br>
                <label for="values">请输入物品价值 （以逗号分隔）：</label>
                <input type="text" id="values" name="values"> <br>
                <label for="w">请输入背包容量 (w)：</label>
                <input type="number" id="w" name="w" required min="1">
            </div>
            <button type="submit">生成实例</button>
        </form>

        {% if result %}
            <div class="result">
            {% if result.error %}
                <p class="error">
                    错误信息: {{ result.error }}
                </p>
            {% else %}
                <p class="success">
                    <ul class="item-list">
                        {% for i in result %}
                            <li>
                                物品：<span class="item-name">{{ i.item }}</span>，
                                重量：<span class="item-weight">{{ i.weight }}</span>，
                                价值：<span class="item-value">{{ i.value }}</span>
                            </li>
                        {% endfor %}
                    </ul>
                    背包容量：<span class="capacity">{{ capacity }}</span>
                </p>
            {% endif %}
            </div>
        {% endif %}
        <button><a href="{% url 'experiment3' %}" style="text-decoration: none; color: white">返回上一页</a></button>
    </div>
</body>
</html>
